import { Source, Meta } from '@storybook/blocks';

<Meta title="HOOKS/useHass/callService" />

# callService()
###### `callService(args: CallServiceArgs<SnakeOrCamelDomain, DomainService<SnakeOrCamelDomain>>)`
The call service helper will allow you to trigger any action in home assistant.

If you have typescript, there's full intellisense on a large range of domains/service/data, if not, you can use developer tools enabled in home assistant,
navigate to this inside your instance, here you'll see a dropdown list and if you open this you'll see there's a "sub title" under each dropdown option, eg "climate.turn_on", in this particular example, "climate" is the domain and "turn_on" is the service.

This is an easy way to visualize all the available domains/service for your home assistant instance.

Additionally you could also use the [Playground](/story/introduction-testconnection--playground) to show you what's available.

### Definition
<Source dark language="ts" code={`callService({
  domain: SnakeOrCamelDomains; // "climate", "light" etc
  service: DomainService<SnakeOrCamelDomains>; // "turn_on", "turnOn",  "toggle" etc
  serviceData?: CallServiceArgs<SnakeOrCamelDomains, DomainService<SnakeOrCamelDomains>>; // any data to pass to the request
  target?: {
    entity_id?: string | string[];
    device_id?: string | string[];
    area_id?: string | string[];
  } | string | string[] // if a string or string[] is passed it's automatically mapped back to entity_id
})`} />

### Example Usage

```ts
function CallServiceExample() {
  const { callService } = useHass();
  const turnOnAC = useCallback(() => {
    callService({
      domain: 'climate',
      service: 'turn_on',
      target: {
        entity_id: 'climate.air_conditioner'
      }
    })
  }, [callService]);
  // can now access all properties relating to the light
  return <Button onClick={toggleClimate}>
    TURN ON CONDITIONER
  </Button>
}
